package cn.jy.careuplusdoctor.adapter;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.jy.careuplusdoctor.R;
import cn.jy.careuplusdoctor.entity.Hospital;

public class HospitalListAdapter  extends BaseAdapter{
	private Activity activity;
	private List<Hospital> list ;
	private LayoutInflater inflater;
	public HospitalListAdapter(Activity activity) {
		setActivity(activity);
		inflater = getActivity().getLayoutInflater();
		list = new ArrayList<Hospital>() ;
	}

	public Activity getActivity() {
		return activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder _holder;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.item_hospital, null);
			_holder = new Holder();
			_holder.txt_itme_hospital = (TextView)convertView.findViewById(R.id.txt_itme_hospital);
			convertView.setTag(_holder);
		} else {
			_holder = (Holder) convertView.getTag();
		}
		_holder.txt_itme_hospital.setText(list.get(position).getHospitalName());
		return convertView;
	}
	public class Holder{
		private TextView txt_itme_hospital;
	}
	public void addAll(List<Hospital> list) {
		if (list!= null) {
			this.list.clear();
			this.list.addAll(list);
			notifyDataSetChanged();
		}
	}

	public List<Hospital> getList() {
		return list;
	}

	public void setList(List<Hospital> list) {
		this.list = list;
	}
	
	public void clearData() {
		this.list.clear();
	}
}
